

gl path "~/Dropbox/CovidTurnout/replication"


///////////////////
// 2020
///////////////////

* Bring in voter data
use "$path/original_data/tx_propensity.dta", clear
keep if county != "HARRIS"

* Generate indicators
gen voted2020 = method20 != .
gen absentee2020 = method20 == 1

gen voted2016 = method16 != .
gen absentee2016 = method16 == 1

gen voted2018 = method18 != . 
gen absentee2018 = method18 == 1

gen voted2014 = method14 != . 
gen absentee2014 = method14 == 1

* Generate running variable
gen running_2020 = mdy(11, 03, 2020) - mdy(month(dob20), day(dob20), year(dob20) + 65)
gen running_2016 = mdy(11, 06, 2016) - mdy(month(dob16), day(dob16), year(dob16) + 65)
gen running_2018 = mdy(11, 06, 2018) - mdy(month(dob20), day(dob20), year(dob20) + 65)
gen running_2014 = mdy(11, 04, 2014) - mdy(month(dob20), day(dob20), year(dob20) + 65)

local bw = 700

* TURNOUT ANALYSIS -----------------------------------
forvalues j = 2014 (2) 2020 {
    preserve
    
    if `j' == 2016 keep if method12 != .
    if `j' == 2020 keep if method16 != .
	if `j' == 2014 keep if method12 != .
	if `j' == 2018 keep if method16 != .
    
    keep if inrange(running_`j', -`bw', `bw')
    
    rdrobust voted`j' running_`j'
    local effectv`j' = e(tau_bc) * 100
    local effectv`j'se = e(se_tau_rb) * 100
    local effectv`j'bwl = e(h_l)
    local effectv`j'bwr = e(h_r)
    local effectv`j'n = e(N_h_l) + e(N_h_r)

    rdrobust absentee`j' running_`j'
    local effecta`j' = e(tau_bc) * 100
    local effecta`j'se = e(se_tau_rb) * 100
    local effecta`j'bwl = e(h_l)
    local effecta`j'bwr = e(h_r)
    local effecta`j'n = e(N_h_l) + e(N_h_r)

    restore
}  

* COMPILE TABLE
quietly {
    cap log close
    set linesize 255

    log using "$path/output/day_rd_table.tex", text replace
    
    noisily dis "\begin{table}[!ht]"
    noisily dis "\centering"
    noisily dis "\caption{\textbf{Day-level RD Shows Very Small Effects on Turnout, Large Effects on Absentee Share.} \label{tab:day_rd_table}}"
    noisily dis "\begin{tabular}{lcccccccc}"
    noisily dis "\toprule \toprule"
    noisily dis " & \multicolumn{4}{c}{{Turnout [0-100]}} & \multicolumn{4}{c}{\% Absentee [0-100]} \\[2mm]"
    noisily dis " & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\[2mm]"
    noisily dis "\cmidrule(lr){2-5} \cmidrule(lr){6-9}"
    noisily dis " Year & 2014 & 2016 & 2018 & 2020 & 2014 & 2016 & 2018 &2020 \\"
    noisily dis "\midrule"
    noisily dis "Age 65+ at Election & {" %3.2f `effectv2014' "} & {" %3.2f `effectv2016' "} & {" %3.2f `effectv2018' "} & {" %3.2f `effectv2020' "} & {" %3.2f `effecta2014' "} & {" %3.2f `effecta2016' "} & {" %3.2f `effecta2018' "} & {" %3.2f `effecta2020' "} \\"
    noisily dis " & ("%3.2f `effectv2014se' ") & ("%3.2f `effectv2016se' ") & ("%3.2f `effectv2018se' ") & (" %3.2f `effectv2020se' ") & ("%3.2f `effecta2014se' ") & ("%3.2f `effecta2016se' ") & ("%3.2f `effecta2018se' ") & (" %3.2f `effecta2020se' ") \\[2mm]"
    noisily dis " BW (left) & {" %3.0f `effectv2014bwl' "} & {" %3.0f `effectv2016bwl' "} & {" %3.0f `effectv2018bwl' "} & {" %3.0f `effectv2020bwl' "} & {" %3.0f `effecta2014bwl' "} & {" %3.0f `effecta2016bwl' "} & {" %3.0f `effecta2018bwl' "} & {" %3.0f `effecta2020bwl' "} \\"
    noisily dis " BW (right) & {" %3.0f `effectv2014bwr' "} & {" %3.0f `effectv2016bwr' "} & {" %3.0f `effectv2018bwr' "} & {" %3.0f `effectv2020bwr' "} & {" %3.0f `effecta2014bwr' "} & {" %3.0f `effecta2016bwr' "} & {" %3.0f `effecta2018bwr' "} & {" %3.0f `effecta2020bwr' "} \\"
    noisily dis " N & {" %6.0fc `effectv2014n' "} & {" %6.0fc `effectv2016n' "} & {" %6.0fc `effectv2018n' "} & {" %6.0fc `effectv2020n' "} & {" %5.0fc `effecta2014n' "} & {" %5.0fc `effecta2016n' "} & {" %5.0fc `effecta2018n' "} & {" %6.0fc `effecta2020n' "} \\"
    noisily dis "\bottomrule \bottomrule"
    noisily dis "\multicolumn{9}{l}{\footnotesize Robust standard errors in parentheses. } \\"
    noisily dis "\multicolumn{9}{l}{\footnotesize Unit of observation is an individual voter in an election year.} \\"
    noisily dis "\multicolumn{9}{l}{\footnotesize Age 65+ at Election is a binary indicator if voter was 65 years or older at the time of the election.} \\"
    noisily dis "\end{tabular}"
    noisily dis "\end{table}"
    
    log off
}

